<template>
  <div>
    <el-dialog title="添加栏目" :visible.sync="buttontype" @close="fun(tname)">
      <div>
        <el-form ref="form" :model="form" label-width="80px">
          <!-- 角色名称 -->
          <el-form-item label="栏目名称">
            <el-input v-model="form.name"></el-input>
          </el-form-item>
          <!-- 角色编码 -->
          <el-form-item label="栏目编码">
            <el-input v-model="form.code"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="upuser">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { http, channel } from "../../api/api";
export default {
  props: ["type", "fun", "tname", "tablerow"],
  data() {
    return {
      buttontype: this.type, //模态框状态
      form: {
        //数据
        name: "", //栏目名称
        code: "", // 栏目编码
      },
    };
  },
  methods: {
    upuser() {
      //  添加用户
      var type = true;
      for (var i in this.form) {
        if (this.form[i] === "") {
          type = false;
        }
      }
      if (type) {
        this.$http.post(http + channel, this.form, { emulateJSON: true }).then(
          (data) => {
            if (data.data.msg == "成功") {
              this.buttontype = false;
              for (var i in this.form) {
                this.form[i] = "";
              }
            }
          },
          (error) => {
            this.$message({
              showClose: true,
              message: error.data.message,
              type: "error",
              center: true,
            });
          }
        );
      } else {
        this.$message.error("请补全信息");
      }
    },
  },
  watch: {
    type() {
      this.buttontype = this.type;
    },
  },
};
</script>

<style>
</style>